package o;

import com.huawei.hwid.core.constants.HwAccountConstants;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;

public final class atp {
    static final Type[] ˏ = new Type[0];

    static final class a implements ParameterizedType, Serializable {
        private final Type[] ˊ;
        private final Type ˋ;
        private final Type ˎ;

        public a(Type type, Type type2, Type... typeArr) {
            int i;
            int i2 = 0;
            if (type2 instanceof Class) {
                boolean z;
                Class cls = (Class) type2;
                i = (Modifier.isStatic(cls.getModifiers()) || cls.getEnclosingClass() == null) ? 1 : 0;
                if (type == null && i == 0) {
                    z = false;
                } else {
                    z = true;
                }
                atr.ˊ(z);
            }
            this.ˎ = type == null ? null : atp.ॱ(type);
            this.ˋ = atp.ॱ(type2);
            this.ˊ = (Type[]) typeArr.clone();
            i = this.ˊ.length;
            while (i2 < i) {
                atr.ˊ(this.ˊ[i2]);
                atp.ʻ(this.ˊ[i2]);
                this.ˊ[i2] = atp.ॱ(this.ˊ[i2]);
                i2++;
            }
        }

        public Type[] getActualTypeArguments() {
            return (Type[]) this.ˊ.clone();
        }

        public Type getRawType() {
            return this.ˋ;
        }

        public Type getOwnerType() {
            return this.ˎ;
        }

        public boolean equals(Object obj) {
            return (obj instanceof ParameterizedType) && atp.ˊ(this, (ParameterizedType) obj);
        }

        public int hashCode() {
            return (Arrays.hashCode(this.ˊ) ^ this.ˋ.hashCode()) ^ atp.ॱ(this.ˎ);
        }

        public String toString() {
            int length = this.ˊ.length;
            if (length == 0) {
                return atp.ʼ(this.ˋ);
            }
            StringBuilder stringBuilder = new StringBuilder((length + 1) * 30);
            stringBuilder.append(atp.ʼ(this.ˋ)).append("<").append(atp.ʼ(this.ˊ[0]));
            for (int i = 1; i < length; i++) {
                stringBuilder.append(", ").append(atp.ʼ(this.ˊ[i]));
            }
            return stringBuilder.append(">").toString();
        }
    }

    static final class c implements WildcardType, Serializable {
        private final Type ˊ;
        private final Type ˏ;

        public c(Type[] typeArr, Type[] typeArr2) {
            boolean z;
            boolean z2 = true;
            atr.ˊ(typeArr2.length <= 1);
            if (typeArr.length == 1) {
                z = true;
            } else {
                z = false;
            }
            atr.ˊ(z);
            if (typeArr2.length == 1) {
                atr.ˊ(typeArr2[0]);
                atp.ʻ(typeArr2[0]);
                if (typeArr[0] != Object.class) {
                    z2 = false;
                }
                atr.ˊ(z2);
                this.ˊ = atp.ॱ(typeArr2[0]);
                this.ˏ = Object.class;
                return;
            }
            atr.ˊ(typeArr[0]);
            atp.ʻ(typeArr[0]);
            this.ˊ = null;
            this.ˏ = atp.ॱ(typeArr[0]);
        }

        public Type[] getUpperBounds() {
            return new Type[]{this.ˏ};
        }

        public Type[] getLowerBounds() {
            if (this.ˊ == null) {
                return atp.ˏ;
            }
            return new Type[]{this.ˊ};
        }

        public boolean equals(Object obj) {
            return (obj instanceof WildcardType) && atp.ˊ(this, (WildcardType) obj);
        }

        public int hashCode() {
            return (this.ˊ != null ? this.ˊ.hashCode() + 31 : 1) ^ (this.ˏ.hashCode() + 31);
        }

        public String toString() {
            if (this.ˊ != null) {
                return "? super " + atp.ʼ(this.ˊ);
            }
            if (this.ˏ == Object.class) {
                return "?";
            }
            return "? extends " + atp.ʼ(this.ˏ);
        }
    }

    static final class e implements GenericArrayType, Serializable {
        private final Type ॱ;

        public e(Type type) {
            this.ॱ = atp.ॱ(type);
        }

        public Type getGenericComponentType() {
            return this.ॱ;
        }

        public boolean equals(Object obj) {
            return (obj instanceof GenericArrayType) && atp.ˊ(this, (GenericArrayType) obj);
        }

        public int hashCode() {
            return this.ॱ.hashCode();
        }

        public String toString() {
            return atp.ʼ(this.ॱ) + "[]";
        }
    }

    public static ParameterizedType ˏ(Type type, Type type2, Type... typeArr) {
        return new a(type, type2, typeArr);
    }

    public static GenericArrayType ˎ(Type type) {
        return new e(type);
    }

    public static WildcardType ˋ(Type type) {
        return new c(type instanceof WildcardType ? ((WildcardType) type).getUpperBounds() : new Type[]{type}, ˏ);
    }

    public static WildcardType ˊ(Type type) {
        return new c(new Type[]{Object.class}, type instanceof WildcardType ? ((WildcardType) type).getLowerBounds() : new Type[]{type});
    }

    public static Type ॱ(Type type) {
        if (type instanceof Class) {
            e eVar;
            Class cls = (Class) type;
            if (cls.isArray()) {
                eVar = new e(ॱ(cls.getComponentType()));
            } else {
                Object obj = cls;
            }
            return eVar;
        } else if (type instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) type;
            return new a(parameterizedType.getOwnerType(), parameterizedType.getRawType(), parameterizedType.getActualTypeArguments());
        } else if (type instanceof GenericArrayType) {
            return new e(((GenericArrayType) type).getGenericComponentType());
        } else {
            if (!(type instanceof WildcardType)) {
                return type;
            }
            WildcardType wildcardType = (WildcardType) type;
            return new c(wildcardType.getUpperBounds(), wildcardType.getLowerBounds());
        }
    }

    public static Class<?> ˏ(Type type) {
        if (type instanceof Class) {
            return (Class) type;
        }
        if (type instanceof ParameterizedType) {
            Type rawType = ((ParameterizedType) type).getRawType();
            atr.ˊ(rawType instanceof Class);
            return (Class) rawType;
        } else if (type instanceof GenericArrayType) {
            return Array.newInstance(ˏ(((GenericArrayType) type).getGenericComponentType()), 0).getClass();
        } else {
            if (type instanceof TypeVariable) {
                return Object.class;
            }
            if (type instanceof WildcardType) {
                return ˏ(((WildcardType) type).getUpperBounds()[0]);
            }
            throw new IllegalArgumentException("Expected a Class, ParameterizedType, or GenericArrayType, but <" + type + "> is of type " + (type == null ? HwAccountConstants.NULL : type.getClass().getName()));
        }
    }

    static boolean ˏ(Object obj, Object obj2) {
        return obj == obj2 || (obj != null && obj.equals(obj2));
    }

    public static boolean ˊ(Type type, Type type2) {
        boolean z = true;
        if (type == type2) {
            return true;
        }
        if (type instanceof Class) {
            return type.equals(type2);
        }
        if (type instanceof ParameterizedType) {
            if (!(type2 instanceof ParameterizedType)) {
                return false;
            }
            ParameterizedType parameterizedType = (ParameterizedType) type;
            ParameterizedType parameterizedType2 = (ParameterizedType) type2;
            if (!(ˏ(parameterizedType.getOwnerType(), parameterizedType2.getOwnerType()) && parameterizedType.getRawType().equals(parameterizedType2.getRawType()) && Arrays.equals(parameterizedType.getActualTypeArguments(), parameterizedType2.getActualTypeArguments()))) {
                z = false;
            }
            return z;
        } else if (type instanceof GenericArrayType) {
            if (!(type2 instanceof GenericArrayType)) {
                return false;
            }
            return ˊ(((GenericArrayType) type).getGenericComponentType(), ((GenericArrayType) type2).getGenericComponentType());
        } else if (type instanceof WildcardType) {
            if (!(type2 instanceof WildcardType)) {
                return false;
            }
            WildcardType wildcardType = (WildcardType) type;
            WildcardType wildcardType2 = (WildcardType) type2;
            if (!(Arrays.equals(wildcardType.getUpperBounds(), wildcardType2.getUpperBounds()) && Arrays.equals(wildcardType.getLowerBounds(), wildcardType2.getLowerBounds()))) {
                z = false;
            }
            return z;
        } else if (!(type instanceof TypeVariable) || !(type2 instanceof TypeVariable)) {
            return false;
        } else {
            TypeVariable typeVariable = (TypeVariable) type;
            TypeVariable typeVariable2 = (TypeVariable) type2;
            if (!(typeVariable.getGenericDeclaration() == typeVariable2.getGenericDeclaration() && typeVariable.getName().equals(typeVariable2.getName()))) {
                z = false;
            }
            return z;
        }
    }

    static int ॱ(Object obj) {
        return obj != null ? obj.hashCode() : 0;
    }

    public static String ʼ(Type type) {
        return type instanceof Class ? ((Class) type).getName() : type.toString();
    }

    static Type ˋ(Type type, Class<?> cls, Class<?> cls2) {
        if (cls2 == cls) {
            return type;
        }
        if (cls2.isInterface()) {
            Class[] interfaces = cls.getInterfaces();
            int length = interfaces.length;
            for (int i = 0; i < length; i++) {
                if (interfaces[i] == cls2) {
                    return cls.getGenericInterfaces()[i];
                }
                if (cls2.isAssignableFrom(interfaces[i])) {
                    return ˋ(cls.getGenericInterfaces()[i], interfaces[i], cls2);
                }
            }
        }
        if (!cls.isInterface()) {
            while (cls != Object.class) {
                Class<?> superclass = cls.getSuperclass();
                if (superclass == cls2) {
                    return cls.getGenericSuperclass();
                }
                if (cls2.isAssignableFrom(superclass)) {
                    return ˋ(cls.getGenericSuperclass(), superclass, cls2);
                }
                cls = superclass;
            }
        }
        return cls2;
    }

    static Type ॱ(Type type, Class<?> cls, Class<?> cls2) {
        if (type instanceof WildcardType) {
            type = ((WildcardType) type).getUpperBounds()[0];
        }
        atr.ˊ(cls2.isAssignableFrom(cls));
        return ˊ(type, (Class) cls, ˋ(type, cls, cls2));
    }

    public static Type ʽ(Type type) {
        if (type instanceof GenericArrayType) {
            return ((GenericArrayType) type).getGenericComponentType();
        }
        return ((Class) type).getComponentType();
    }

    public static Type ˎ(Type type, Class<?> cls) {
        Type ॱ = ॱ(type, cls, Collection.class);
        if (ॱ instanceof WildcardType) {
            ॱ = ((WildcardType) ॱ).getUpperBounds()[0];
        }
        if (ॱ instanceof ParameterizedType) {
            return ((ParameterizedType) ॱ).getActualTypeArguments()[0];
        }
        return Object.class;
    }

    public static Type[] ˋ(Type type, Class<?> cls) {
        if (type == Properties.class) {
            return new Type[]{String.class, String.class};
        }
        Type ॱ = ॱ(type, cls, Map.class);
        if (ॱ instanceof ParameterizedType) {
            return ((ParameterizedType) ॱ).getActualTypeArguments();
        }
        return new Type[]{Object.class, Object.class};
    }

    public static Type ˊ(Type type, Class<?> cls, Type type2) {
        return ˋ(type, cls, type2, new HashSet());
    }

    private static Type ˋ(Type type, Class<?> cls, Type type2, Collection<TypeVariable> collection) {
        Type type3 = type2;
        while (type3 instanceof TypeVariable) {
            Type type4 = (TypeVariable) type3;
            if (collection.contains(type4)) {
                return type3;
            }
            collection.add(type4);
            type3 = ˊ(type, (Class) cls, (TypeVariable) type4);
            if (type3 == type4) {
                return type3;
            }
        }
        Type ˋ;
        if ((type3 instanceof Class) && ((Class) type3).isArray()) {
            Class cls2 = (Class) type3;
            type4 = cls2.getComponentType();
            ˋ = ˋ(type, cls, type4, collection);
            if (type4 != ˋ) {
                return ˎ(ˋ);
            }
            return cls2;
        } else if (type3 instanceof GenericArrayType) {
            GenericArrayType genericArrayType = (GenericArrayType) type3;
            type4 = genericArrayType.getGenericComponentType();
            ˋ = ˋ(type, cls, type4, collection);
            if (type4 != ˋ) {
                return ˎ(ˋ);
            }
            return genericArrayType;
        } else if (type3 instanceof ParameterizedType) {
            int i;
            ParameterizedType parameterizedType = (ParameterizedType) type3;
            type4 = parameterizedType.getOwnerType();
            Type ˋ2 = ˋ(type, cls, type4, collection);
            if (ˋ2 != type4) {
                i = 1;
            } else {
                i = 0;
            }
            r4 = parameterizedType.getActualTypeArguments();
            int length = r4.length;
            int i2 = i;
            r0 = r4;
            for (int i3 = 0; i3 < length; i3++) {
                Type ˋ3 = ˋ(type, cls, r0[i3], collection);
                if (ˋ3 != r0[i3]) {
                    if (i2 == 0) {
                        r0 = (Type[]) r0.clone();
                        i2 = 1;
                    }
                    r0[i3] = ˋ3;
                }
            }
            if (i2 != 0) {
                return ˏ(ˋ2, parameterizedType.getRawType(), r0);
            }
            return parameterizedType;
        } else if (!(type3 instanceof WildcardType)) {
            return type3;
        } else {
            WildcardType wildcardType = (WildcardType) type3;
            r0 = wildcardType.getLowerBounds();
            r4 = wildcardType.getUpperBounds();
            if (r0.length == 1) {
                ˋ = ˋ(type, cls, r0[0], collection);
                if (ˋ != r0[0]) {
                    return ˊ(ˋ);
                }
                return wildcardType;
            } else if (r4.length != 1) {
                return wildcardType;
            } else {
                type4 = ˋ(type, cls, r4[0], collection);
                if (type4 != r4[0]) {
                    return ˋ(type4);
                }
                return wildcardType;
            }
        }
    }

    static Type ˊ(Type type, Class<?> cls, TypeVariable<?> typeVariable) {
        Class ˊ = ˊ((TypeVariable) typeVariable);
        if (ˊ == null) {
            return typeVariable;
        }
        Type ˋ = ˋ(type, cls, ˊ);
        if (!(ˋ instanceof ParameterizedType)) {
            return typeVariable;
        }
        return ((ParameterizedType) ˋ).getActualTypeArguments()[ˏ(ˊ.getTypeParameters(), (Object) typeVariable)];
    }

    private static int ˏ(Object[] objArr, Object obj) {
        int length = objArr.length;
        for (int i = 0; i < length; i++) {
            if (obj.equals(objArr[i])) {
                return i;
            }
        }
        throw new NoSuchElementException();
    }

    private static Class<?> ˊ(TypeVariable<?> typeVariable) {
        GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
        return genericDeclaration instanceof Class ? (Class) genericDeclaration : null;
    }

    static void ʻ(Type type) {
        boolean z = ((type instanceof Class) && ((Class) type).isPrimitive()) ? false : true;
        atr.ˊ(z);
    }
}
